/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.kaoshi.myweb.web.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.kaoshi.myweb.web.entity.Task;
import com.kaoshi.myweb.web.repository.TaskDao;




@Component
public class TaskService {
	
	@Autowired
	private TaskDao taskDao;

	public Task getTask(Long id) {
		return taskDao.queryById(id);
	}

	public void saveTask(Task entity) {
		taskDao.insert(entity);
	}

	public void deleteTask(Long id) {
		taskDao.deleteById(id);
	}

	public List<Task> getAllTask() {
		return (List<Task>) taskDao.getAllTask();
	}

//	public Page<Task> getUserTask(Long userId, Map<String, Object> searchParams, int pageNumber, int pageSize,
//			String sortType) {
//		PageRequest pageRequest = buildPageRequest(pageNumber, pageSize, sortType);
//		Specification<Task> spec = buildSpecification(userId, searchParams);
//
//		return taskDao.findAll(spec, pageRequest);
//	}
//
//	/**
//	 * 创建分页请求.
//	 */
//	private PageRequest buildPageRequest(int pageNumber, int pagzSize, String sortType) {
//		Sort sort = null;
//		if ("auto".equals(sortType)) {
//			sort = new Sort(Direction.DESC, "id");
//		} else if ("title".equals(sortType)) {
//			sort = new Sort(Direction.ASC, "title");
//		}
//
//		return new PageRequest(pageNumber - 1, pagzSize, sort);
//	}
//
//	/**
//	 * 创建动态查询条件组合.
//	 */
//	private Specification<Task> buildSpecification(Long userId, Map<String, Object> searchParams) {
//		Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
//		filters.put("user.id", new SearchFilter("user.id", Operator.EQ, userId));
//		Specification<Task> spec = DynamicSpecifications.bySearchFilter(filters.values(), Task.class);
//		return spec;
//	}
}
